﻿using Styx;

using Styx.CommonBot.Routines;
using Styx.Helpers;
using Styx.WoWInternals;
using Styx.WoWInternals.WoWObjects;
using Styx.TreeSharp;
using Action = Styx.TreeSharp.Action;

using CommonBehaviors.Actions;

namespace Crusader
{
    partial class Routine: CombatRoutine
    {

        partial class Paladin
        {

            #region Combat composites


            public static Composite ProtectionCombatBehavior()
            {
                return new Decorator(ret => Me.CurrentTarget != null && !Me.Mounted,
                    new PrioritySelector(

                        AutoAttack(),

                        CastCooldown("Ardent Defender", ret => Me.HealthPercent <= Crusader.Settings.Instance.Paladin_Prot_UseAD),
                        CastCooldown("Lay on Hands", ret => Me.HealthPercent <= Crusader.Settings.Instance.Paladin_Prot_UseLoH && !PlayerHasBuff("Ardent Defender")),

                        CastSpell("Word of Glory", Me, ret => CurrentHolyPower() >= 3 && Me.HealthPercent < Crusader.Settings.Instance.Paladin_Prot_WoG),
                        CastSpell("Eternal Flame", Me, ret => CurrentHolyPower() >= 3 && Me.HealthPercent < Crusader.Settings.Instance.Paladin_Prot_WoG),
                        CastSpell("Flash of Light", Me, ret => PlayerHasBuffStacks("Selfless Healer") >= 3 && Me.HealthPercent < Crusader.Settings.Instance.Paladin_Prot_WoG),

                        CastSpellButFail("Shield of the Righteous", ret => CurrentHolyPower() >= 3 || PlayerHasBuff("Divine Purpose")),

                        //CS>J>AS+>Cons>L90>AS>HW

                        CastSpell("Hammer of the Righteous", ret => EnemyUnits.Count > 1 || Crusader.Settings.Instance.Paladin_Prot_WeakenedBlows && TargetDebuffTimeLeft("Weakened Blows", false) < 1.5),
                        CastSpell("Crusader Strike"),

                        CastSpell("Seal of Righteousness", ret => (Crusader.Settings.Instance.Paladin_Seal == Seal.SoR || Crusader.Settings.Instance.Paladin_Seal == Seal.Auto && (EnemyUnits.Count > Crusader.Settings.Instance.Paladin_Prot_SealSwitch) && !Me.HasAura("Seal of Righteousness"))),
                        CastSpell("Seal of Truth", ret => (Crusader.Settings.Instance.Paladin_Seal == Seal.SoT || Crusader.Settings.Instance.Paladin_Seal == Seal.Auto && (EnemyUnits.Count < Crusader.Settings.Instance.Paladin_Prot_SealSwitch) && !Me.HasAura("Seal of Truth"))),

                        new Decorator(ret => SpellCooldown("Crusader Strike") > 1.5,
                            new PrioritySelector(
                                CastSpell("Judgment"),
                                CastSpell("Avenger's Shield", ret=> PlayerHasBuff("Grand Crusader")),
                                CastOnGround("Consecration", ret => StyxWoW.Me.CurrentTarget.Location, ret => PlayerHasGlyph("Consecration")),
                                CastSpell("Consecration", ret => !PlayerHasGlyph("Consecration")),//, ret => Me.ManaPercent > 65 || EnemyUnits.Count > 3),
                                CastSpell("Execution Sentence"),
                                CastSpell("Holy Prism"),
                                CastOnGround("Light's Hammer", ret => StyxWoW.Me.CurrentTarget.Location, ret => Crusader.Settings.Instance.AllowAoE),
                                CastSpell("Avenger's Shield"),
                                CastSpell("Holy Wrath", ret => !CanCastSpell("Consecration"))//, ret => Me.ManaPercent > 50 || EnemyUnits.Count > 3),
                                )),


                        CastSpell("Shield of the Righteous", ret => CurrentHolyPower() >= 3 || PlayerHasBuff("Divine Purpose")),

                        CastSpell("Sacred Shield", Me, ret => Crusader.Settings.Instance.Paladin_Prot_UseSS && PlayerBuffTimeLeft(20925) < 2)

                        /* */
                        ,
                        UseTrinket1("Avenging Wrath"),
                        UseTrinket2("Avenging Wrath"),
                        UseGloves("Avenging Wrath")//*/

                    )
                );
            }

            #endregion
        }
    }
}